package com.bigknow.appstore.web.base.entity;

import com.bigknow.appstore.web.base.entity.enums.State;
import com.bigknow.appstore.web.framework.entity.IFancyTreeEntity;
import com.bigknow.appstore.web.framework.entity.ITreeEntity;
import com.bigknow.appstore.web.framework.entity.QueryField;
import com.bigknow.appstore.web.framework.entity.BaseEntity;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Indexed;
import org.mongodb.morphia.annotations.Transient;

import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement
@Entity("web.base.permission")
public class Permission extends BaseEntity implements ITreeEntity<Permission>, IFancyTreeEntity<Permission> {
    public static final long serialVersionUID = 1L;
    @QueryField
    @Indexed(unique = true)
    private String code;
    @QueryField
    private String name;
    @QueryField
    private String parentCode;
    @Transient
    private String parentName;
    @QueryField
    private String description;
    private String pageUrl;

    public enum Type {
        MENU, ACTION, DATA
    }

    private Type type;
    private Integer sort;
    private String iconCss;
    private State state;
    @Transient
    private List<Permission> children = new ArrayList<>();
    @Transient
    private Boolean selected;

    @Override
    public String getTitle() {
        return name;
    }

    @Override
    public String getKey() {
        return this.getId();
    }

    @Override
    public boolean getFolder() {
        if (children != null && !children.isEmpty()) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Boolean getSelected() {
        return selected;
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    public void setName(String value) {
        this.name = value;
    }

    public String getName() {
        return this.name;
    }

    public void setParentCode(String value) {
        this.parentCode = value;
    }

    public String getParentCode() {
        return this.parentCode;
    }

    public void setDescription(String value) {
        this.description = value;
    }

    public String getDescription() {
        return this.description;
    }

    public void setPageUrl(String value) {
        this.pageUrl = value;
    }

    public String getPageUrl() {
        return this.pageUrl;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getIconCss() {
        return iconCss;
    }

    public void setIconCss(String iconCss) {
        this.iconCss = iconCss;
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public List<Permission> getChildren() {
        return children;
    }

    public void setChildren(List<Permission> children) {
        this.children = children;
    }
}

	
